<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        小于距今天数：<el-input v-model="query.fromNowDay" size="small" clearable placeholder="输入小于距今天数搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        大于于距今天数：<el-input v-model="query.greaterFromNowDay" size="small" clearable placeholder="输入大于距今天数搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        出货次数&lt;= <el-input v-model="query.purchaseTime" size="small" clearable placeholder="输入小于出货次数搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation />
      </div>
      <crudOperation :permission="permission"></crudOperation>
      <!--表单组件-->
      <!-- <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="ID">
            <el-input v-model="form.id" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="型号">
            <el-input v-model="form.model" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="距今天数">
            <el-input v-model="form.fromNowDay" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="采购次数">
            <el-input v-model="form.purchaseTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="创建者">
            <el-input v-model="form.createBy" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="更新者">
            <el-input v-model="form.updateBy" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="创建日期">
            <el-input v-model="form.createTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="更新时间">
            <el-input v-model="form.updateTime" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog> -->
      <el-dialog :visible.sync="dialog" title="采购清单详情" append-to-body top="30px" width="85%">
        <el-table ref="detailTable" :data="errorInfo" size="small" style="width: 100%;">
          <!-- <el-table-column prop="index" label="序号" /> -->
          <el-table-column prop="b2b" label="b2b号" />
          <el-table-column prop="model" label="型号" />
          <el-table-column prop="quantity" label="采购数量" />
          <!-- <el-table-column prop="expectedDeliveryDate" label="期望交付日" />
          <el-table-column prop="remark" label="备注" /> -->
          <el-table-column prop="customer" label="客户" />
          <el-table-column prop="createTime" label="采购日期" />
        </el-table>
      </el-dialog>      
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column type="index" label="序号" :index="indexMethod" />  
        <el-table-column prop="model" label="型号" />
        <el-table-column prop="fromNowDay" label="小于距今天数" />
        <el-table-column prop="greaterFromNowDay" label="大于距今天数" />
        <el-table-column prop="purchaseTime" label="采购次数" />
        <el-table-column prop="quantity" label="采购数量" />
        <el-table-column label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="info(scope.row.model, scope.row.fromNowDay, scope.row.greaterFromNowDay)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudSalePoorProduct from '@/api/salePoorProduct'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import crudPurchaseData from '@/api/purchaseData'

const defaultForm = { id: null, model: null, fromNowDay: null, greaterFromNowDay: null, purchaseTime: null, createBy: null, updateBy: null, createTime: null, updateTime: null }
export default {
  name: 'SalePoorProduct',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '滞销商品', url: 'api/salePoorProduct', idField: 'id', sort: 'model,desc', crudMethod: { ...crudSalePoorProduct }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'salePoorProduct:add'],
        edit: ['admin', 'salePoorProduct:edit'],
        del: ['admin', 'salePoorProduct:del']
      },
      rules: {
      },
      dialog: false,
      errorInfo: ''
    }
  },
  created() {
    this.crud.optShow = {
      add: false,
      edit: false,
      del: false,
      download: true,
      reset: true
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    indexMethod(index) {
      return (index + 1) + (this.crud.page.page -1) * this.crud.page.size
    },    
    info(model, fromNowDay, greaterFromNowDay) {
      const params = { model: model, fromNowDay: fromNowDay, greaterFromNowDay: greaterFromNowDay, customer: "备" }
      this.dialog = true
      crudPurchaseData.list(params).then(res => {
        this.errorInfo = res
      })
    }
  }
}
</script>

<style scoped>

</style>
